package main

import (
	"log"
	"math/rand"
	"sync"
	"time"
)

var wg sync.WaitGroup

func SayGreetings(greeting string, times int) {
	for i := 0; i < times; i++ {
		time.Sleep(2 * time.Second) // 睡眠2秒
		log.Printf("%v,%d", greeting, i)
	}
	wg.Done()
}

func main() {
	rand.Seed(time.Now().UnixNano())
	log.SetFlags(11)
	wg.Add(2)
	go SayGreetings("hi!", 10)
	go SayGreetings("hello!", 10)
	wg.Wait()
}
